import { getProductList, getProductRate, buyProduct } from '@/api/invest'

// 设置变量
const state = {
  productList:[]
}

const mutations = {
  SET_PRODUCTLIST:(state,list) => {
    state.productList = list
  }
}

const actions = {
    // 获取投资产品列表
    getProductList({ commit }, ) {
      return new Promise((resolve, reject) => {
        getProductList().then(response => {
        console.log('response的值',response)
        commit('SET_PRODUCTLIST', response.data.data)
          resolve(response.data.data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    
    // 获取投资产品利率
    getProductRate({ commit }, data) {
      return new Promise((resolve, reject) => {
        getProductRate(data).then(response => {
          resolve(response.data.data) // 置为成功
        }).catch(error => {
          reject(error) // 报错
        })
      })
    },

    // 购买理财产品
    buyProduct({ commit }, data) {
      return new Promise((resolve, reject) => {
        buyProduct(data).then(response => {
          resolve() // 置为成功
        }).catch(error => {
          reject(error) // 报错
        })
      })
    },
}

// 导入
export default {
    namespaced: true, // 匿名空间，要打开
    actions,
    state,
    mutations
  }